/******************************************************文本框*****************************************************/
/*
依赖
 <link href="/static/lib/datepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
 <script type="text/javascript" src="/static/lib/datepicker/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
 <script type="text/javascript" src="/static/lib/datepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
*/
_$.DateTimePicker=function (target){
    var _this = this;
    _$.DateTimePicker.superclass.constructor.call(_this,target);
};
_$.regClass("DateTimePicker",_$.DateTimePicker);

_$.extend(_$.DateTimePicker,_$.FormItem, {
    _cls:_$._clsPre + "DateTimePicker",
    _uiCls:_$._uiPreCls + "DateTimePicker",
    _attrProps:function(){
        var _this = this;
        var properties = _$.DateTimePicker.superclass._attrProps.call(_this);
        properties.addAll(["view","onchange","inputStyle"]);
        return properties;
    },
    _attrOpts:function(){
        var _this = this;
        var opts = _$.DateTimePicker.superclass._attrOpts.call(_this);
        return $.extend(true,opts,{
            view:2
        });
    },
    _editModel:function(){
        var _this = this;
        _this._clearShow();
        var source='<input type="text" class="DateTimePicker" />';
        _this._replaceNode(source);
        _this.component = $(".DateTimePicker",_this.el);
        _this.el.addClass(_this._uiCls);
        _this._setStyle();
        _this._initDatetimepicker();
        _this.setOption("model",_EDITABLE_);
        _this._init();
        _this._bindEvents();
    },
    _initDatetimepicker:function(){
        var _this = this;
        var view = _this.getOption("view");
        if(0 == view){
            _this.component.datetimepicker({
                format: 'yyyy',
                'language':'zh-CN',
                startView:4,
                autoclose: 1,
                forceParse:0,
                minView:4
            });
        }else if(1 == view){
            _this.component.datetimepicker({
                format: 'yyyy-mm',
                'language':'zh-CN',
                startView:3,
                autoclose: 1,
                forceParse:0,
                minView:3
            });
        }else if(2 == view){
            _this.component.datetimepicker({
                format: 'yyyy-mm-dd',
                'language':'zh-CN',
                startView:2,
                autoclose: 1,
                forceParse:0,
                minView:2
            });
        }else if(3 == view){
            _this.component.datetimepicker({
                format: 'yyyy-mm-dd hh:ii:ss',
                'language':'zh-CN',
                startView:2,
                autoclose: 1,
                forceParse:0,
                minView:1
            });
        }else if(4 == view){
            _this.component.datetimepicker({
                format: 'hh:ii:ss',
                'language':'zh-CN',
                startView:1,
                autoclose: 1,
                forceParse:0,
                minView:0
            });
        }
    },
    _bindEvents:function(){
        var _this = this;
        _$.DateTimePicker.superclass._getEvents.call(_this, ["onblur","onchange"]);
        if(_this._isEdit()){
            var event = {
                "name":_this.id
            };

            _this.component.bind("blur",function(){
                event['source'] = _this.component;
                event['value'] = _this.getValue();
                _this._blurHandler(event);
            });
        }
    },
    _blurHandler:function(event){
        var _this = this;
        _this._fire("onblur",event);
        var original = isNotEmpty(_this.original)?_this.original:_this.getOption("initValue");
        var value = _this.getValue();
        if(original != value){
            _this.original=value;
            _this._fire("onchange",event);
        }
    },
    _setStyle:function(){
        var _this = this;
        var width = _this.getOption('width');
        if(isNotEmpty(width)){
            _this.component.css({
                "width":width + "px"
            });
        }
        var height =_this.getOption('height');
        if(isNotEmpty(height)){
            _this.component.css({
                "height":height + "px"
            });
        }
        var inputStyle = _this.getOption('inputStyle');
        if(isNotEmpty(inputStyle)){
            _$.css(_this.component,inputStyle);
        }
    }
});
